﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfFeeCalculator.FeeWcfService;



namespace WpfFeeCalculator.Controllers
{
    static class ControlHelpers
    {
        public static Task<DataResult> StaticGetPortfolioExcelAsync(this FeeServiceClient svc, Portfolio portfolio, DateTime date, PriceCutOff priceCutOff)
        {
            
            return Task<DataResult>.Factory.FromAsync(
                svc.BeginGetPortfolioExcel, // BeginPart
                svc.EndGetPortfolioExcel,
                portfolio, date, priceCutOff,
                TaskCreationOptions.LongRunning);                     // State, Options
        }

        public static Task<List<PriceCutOff>> StaticGetPriceCutOff(this FeeServiceClient svc, Guid portfolioGuid, DateTime date)
        {
            return Task<List<PriceCutOff>>.Factory.FromAsync(
                svc.BeginGetPriceCutOffs, // BeginPart
                svc.EndGetPriceCutOffsAsList,
                portfolioGuid, date,
                TaskCreationOptions.None);                     // State, Options
        }

        private static List<PriceCutOff> EndGetPriceCutOffsAsList(this FeeServiceClient svc, System.IAsyncResult result)
        {
            return svc.EndGetPriceCutOffs(result).ToList();
        }
    }
}
